import collections

Node = collections.namedtuple('Node', ['id', 'url'])
CLUSTER_SIZE = 3
ELECTION_TIMEOUT_MAX = 5
HEART_BEAT_INTERVAL = 2


class Cluster:
    ids = range(0, CLUSTER_SIZE)
    urls = [f'localhost:800{n}' for n in ids]

    def __init__(self):
        self.cluster_size = CLUSTER_SIZE
        self._nodes = [Node('S' + str(nid + 1), url) for nid, url in enumerate(self.urls, start=0)]

    def __len__(self):
        return len(self._nodes)

    def __getitem__(self, index):
        return self._nodes[index]

    def __repr__(self):
        return ", ".join([f'{n.id}@{n.url}' for n in self._nodes])

    def join(self, node):
        self._nodes.append(node)


if __name__ == '__main__':
    cluster = Cluster()
    print(cluster)
